package com.health.controller;

import com.health.common.Result;
import com.health.entity.Hospital;
import com.health.entity.pojo.PageData;
import com.health.entity.pojo.dto.QueryHospitalDTO;
import com.health.service.IConsultingroomService;
import com.health.service.IHospitalService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.log4j.Log4j;
import lombok.extern.slf4j.Slf4j;
import org.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

/**
 * <p>
 * 医院表 前端控制器
 * </p>
 *
 * @author sanchuan
 * @since 2023-04-16
 */
@RestController
@RequestMapping("/hospital")
@Api(tags = "医院管理")
@Slf4j
public class HospitalController extends BaseController{
    @Autowired
    private IHospitalService hospitalService;

    @Autowired
    private IConsultingroomService consultingroomService;

    @ApiOperation("获得医院列表分页数据+条件查询")
    @PostMapping("/listHospitalPage/{pageNum}/{pageSize}")
    public Result<Hospital> listHospitalPage(
            @PathVariable("pageNum") Integer pageNum,
            @PathVariable("pageSize") Integer pageSize,
            @RequestBody QueryHospitalDTO queryHospitalDTO){
        PageData pageData = hospitalService.listHospitalPage(pageNum, pageSize,queryHospitalDTO);
        return this.dataResult(pageData);
    }

    @ApiOperation("修改医院上架状态")
    @PostMapping("/changeHospitalShelves/{isShelves}/{id}")
    public Result<String> changeHospitalShelves(@PathVariable("isShelves") boolean isShelves, @PathVariable("id") Integer id){
        Boolean result = hospitalService.changeHospitalShelves(isShelves, id);
        return this.dataResult(result);
    }
    @ApiOperation("批量修改医院上架状态")
    @PostMapping("/changeHospitalShelvesMulti/{isShelves}")
    public Result<String> changeHospitalShelvesMulti(@PathVariable("isShelves") boolean isShelves, @RequestBody List<Integer> ids){
        Boolean result = hospitalService.changeHospitalShelvesMulti(isShelves,ids);
        return this.dataResult(result);
    }
    @ApiOperation("批量删除医院")
    @DeleteMapping("/deleteHospitalShelvesMulti")
    public Result<String> deleteHospitalShelvesMulti(@RequestBody List<Integer> ids){
        boolean b = hospitalService.removeBatchByIds(ids);
        return this.dataResult(b);
    }
    @ApiOperation("添加医院")
    @PostMapping("/addHospital")
    public Result<String> addHospital(@RequestBody Hospital hospital){
        boolean b = hospitalService.saveOrUpdate(hospital);
        return this.dataResult(b);
    }

    @ApiOperation("获得医院详情")
    @GetMapping("/getHospitalDetails/{id}")
    public Result<Hospital> getHospitalDetails(@PathVariable("id") Integer id){
        Hospital hospital = hospitalService.getById(id);
        return this.dataResult(hospital);
    }

    @ApiOperation("获得科室列表")
    @GetMapping("/getConsultingRooms")
    public Result<List<List>> getConsultingRooms(){
        List<List> lists = new ArrayList<>();
        List<String> oneList = consultingroomService.getConsultingRoomsOne();
        List<String> twoList = consultingroomService.getConsultingRoomsTwo();
        lists.add(oneList);
        lists.add(twoList);
        return this.dataResult(lists);
    }
}
